import {defineStore} from 'pinia'
import {ImgSelfieAnime} from "@/pojo/ImageEnhancedResult/ImgSelfieAnime.js";
import {
    imageColourize,
    imageDefinitionEnhance,
    imageQualityEnhance,
    imgSelfieAnime,
    imgStyleTrans
} from "@/apis/ImageEnhance.js";
import {ImgStyleTrans} from "@/pojo/ImageEnhancedResult/ImgStyleTrans.js";
import {ImgQualityEnhance} from "@/pojo/ImageEnhancedResult/ImgQualityEnhance.js";
import {ImgDefinitionEnhance} from "@/pojo/ImageEnhancedResult/ImgDefinitionEnhance.js";
import {ImgColourize} from "@/pojo/ImageEnhancedResult/ImgColourize.js";

export const useImageEnhancedStore = defineStore("imageEnhancedStore", () => {

    //人物动漫化
    const selfieAnimeResult = new ImgSelfieAnime()

    //图片风格转换
    const styleTransResult=new ImgStyleTrans()

    //图片无损放大
    const qualityEnhanceResult=new ImgQualityEnhance()

    //图片清晰度增强
    const definitionEnhanceResult=new ImgDefinitionEnhance()

    //黑白图片上色
    const colourizeResult=new ImgColourize()


    const getImgSelfieAnime = async (file) => {

        const formData = new FormData()
        formData.append("file", file)
        //开始请求
        const res = await imgSelfieAnime(formData)

        //获得返回结果
        await selfieAnimeResult.parseJson(res)

        const imageFile = selfieAnimeResult.imageFile
        console.log(imageFile)
        const imageUrl = selfieAnimeResult.imageUrl
        console.log(imageUrl)

    }



    const getImgStyleTrans = async (file,choice) => {



        const formData = new FormData()
        formData.append("file", file)
        //开始请求
        const res = await imgStyleTrans(formData,choice)

        //获得返回结果
        await styleTransResult.parseJson(res)

        const imageFile = styleTransResult.imageFile
        console.log(imageFile)
        const imageUrl = styleTransResult.imageUrl
        console.log(imageUrl)

    }


    const getImageQualityEnhance = async (file) => {

        const formData = new FormData()
        formData.append("file", file)
        //开始请求
        const res = await imageQualityEnhance(formData)

        //获得返回结果
        await qualityEnhanceResult.parseJson(res)

        const imageFile = qualityEnhanceResult.imageFile
        console.log(imageFile)
        const imageUrl = qualityEnhanceResult.imageUrl
        console.log(imageUrl)

    }



    const getImageDefinitionEnhance = async (file) => {

        const formData = new FormData()
        formData.append("file", file)
        //开始请求
        const res = await imageDefinitionEnhance(formData)

        //获得返回结果
        await definitionEnhanceResult.parseJson(res)

        const imageFile = definitionEnhanceResult.imageFile
        console.log(imageFile)
        const imageUrl = definitionEnhanceResult.imageUrl
        console.log(imageUrl)

    }


    const getColourize = async (file) => {

        const formData = new FormData()
        formData.append("file", file)
        //开始请求
        const res = await imageColourize(formData)

        //获得返回结果
        await colourizeResult.parseJson(res)

        const imageFile = colourizeResult.imageFile
        console.log(imageFile)
        const imageUrl = colourizeResult.imageUrl
        console.log(imageUrl)

    }


    return {
        getImgSelfieAnime,
        selfieAnimeResult,
        getImgStyleTrans,
        styleTransResult,
        getImageQualityEnhance,
        qualityEnhanceResult,
        getImageDefinitionEnhance,
        definitionEnhanceResult,
        getColourize,
        colourizeResult
    }

}, {
    persist: true
})